<?php
include 'db.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $id = $_POST['id'];
    $balance = $_POST['balance'];

    $stmt = $pdo->prepare("UPDATE users SET balance = ? WHERE id = ?");
    $stmt->execute([$balance, $id]);

    if ($stmt->rowCount() > 0) {
        echo json_encode(['success' => true, 'message' => '余额更新成功']);
    } else {
        echo json_encode(['success' => false, 'message' => '余额更新失败']);
    }
} else {
    echo json_encode(['success' => false, 'message' => 'Invalid request method']);
}